﻿using SIS.Infrastructures.Context;
using System.Collections.Generic;

namespace SIS.Repositories.Common
{
    public class BaseRepository<T>: IBaseRepository<T> where T : class, new()
    {
        private readonly IDbContext _context;
        public BaseRepository(IDbContext context)
        {
            _context = context;
        }

        public int Insert(T entity)
        {
            return _context.Connection.Insertable(entity).ExecuteReturnIdentity();
        }

        public int Delete(T entity)
        {
            return _context.Connection.Deleteable<T>().Where(entity).ExecuteCommand();
        }

        public IList<T> GetAll()
        {
            return _context.Connection.Queryable<T>().ToList();
        }

        public int Update(T entity)
        {
            return _context.Connection.Updateable(entity).ExecuteCommand();
        }

    }
}
